#
# LuckyBot4, a python IRC bot
# (c) Copyright 2008 by Lucas van Dijk
# http://www.return1.net
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA
#
# $Id: dialogs.py 77 2009-06-06 13:00:28Z luckyluke56 $
#

import gtk
import gtk.glade
import gobject

from gettext import gettext as _

class TableDialog(gtk.Dialog):
	"""
		A simple dialog containing one table with fields
	"""
	
	def __init__(self, title, fields, parent = None, buttons = (gtk.STOCK_OK, 
		gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)):
		"""
			Constructor, creates a new dialog with a table. fields is a
			list in the following format:
			[
				('entryName', 'Label')
			]
		"""
		
		super(TableDialog, self).__init__(title, parent, gtk.DIALOG_MODAL |
			gtk.DIALOG_DESTROY_WITH_PARENT, buttons)
		
		table = gtk.Table(len(fields), 2)
		table.set_border_width(10)
		
		i = 0
		for field, text in fields:			
			label = gtk.Label(_(text))
			label.set_justify(gtk.JUSTIFY_LEFT)
			table.attach(label, 0, 1, i, i+1)
			
			setattr(self, 'txt%s' % field.title(), gtk.Entry())
			
			table.attach(getattr(self, 'txt%s' % field.title()), 1, 2, i, i+1, xpadding=5, ypadding=5)
			
			i += 1
		
		self.vbox.pack_start(table)
		self.show_all()

class AddServerDialog(TableDialog):
	"""
		A simple dialog for entering some server info
	"""
	
	def __init__(self, parent = None):
		"""
			Sets the fields for the table dialog class
		"""	
		
		fields = [
			('hostname', 'Hostname(:port)'),
			('nickname', 'Nickname'),
			('password', 'Nickserv Password'),
			('channels', 'Channels')
		]
		
		super(AddServerDialog, self).__init__(_("Add Server"), fields, parent,
			(gtk.STOCK_ADD, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))

class AddUserDialog(TableDialog):
	"""
		A simple dialog for adding a user
	"""
	
	def __init__(self, parent = None, edit = False):
		"""
			Sets the fields for the table dialog class
		"""	
		
		fields = [
			('nickname', 'Nickname'),
			('password', 'Password')
		]
		
		super(AddUserDialog, self).__init__(_("Add User"), fields, parent,
			(gtk.STOCK_EDIT if edit else gtk.STOCK_ADD, gtk.RESPONSE_OK, 
			gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
		
		
